<html><head><meta charset="utf-8"><title>18 场景集合：并发 List、Map的应用场景-慕课专栏</title>
			<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
			<meta name="renderer" content="webkit">
			<meta property="qc:admins" content="77103107776157736375">
			<meta property="wb:webmaster" content="c4f857219bfae3cb">
			<meta http-equiv="Access-Control-Allow-Origin" content="*">
			<meta http-equiv="Cache-Control" content="no-transform ">
			<meta http-equiv="Cache-Control" content="no-siteapp">
			<link rel="apple-touch-icon" sizes="76x76" href="https://www.imooc.com/static/img/common/touch-icon-ipad.png">
			<link rel="apple-touch-icon" sizes="120x120" href="https://www.imooc.com/static/img/common/touch-icon-iphone-retina.png">
			<link rel="apple-touch-icon" sizes="152x152" href="https://www.imooc.com/static/img/common/touch-icon-ipad-retina.png">
			<link href="https://moco.imooc.com/captcha/style/captcha.min.css" rel="stylesheet">
			<link rel="stylesheet" href="https://www.imooc.com/static/moco/v1.0/dist/css/moco.min.css?t=201907021539" type="text/css">
			<link rel="stylesheet" href="https://www.imooc.com/static/lib/swiper/swiper-3.4.2.min.css?t=201907021539">
			<link rel="stylesheet" href="https://static.mukewang.com/static/css/??base.css,common/common-less.css?t=2.5,column/zhuanlanChapter-less.css?t=2.5,course/inc/course_tipoff-less.css?t=2.5?v=201907051055" type="text/css">
			<link charset="utf-8" rel="stylesheet" href="https://www.imooc.com/static/lib/ueditor/themes/imooc/css/ueditor.css?v=201907021539"><link rel="stylesheet" href="https://www.imooc.com/static/lib/baiduShare/api/css/share_style0_16.css?v=6aba13f0.css"></head>
			<body><div id="main">


<div class="main-con hide-menu">
    <!-- 左侧菜单 & 索引 -->
    
    <div class="right-content" style="padding-left: 0px;">
        <div class="container clearfix" id="top" style="width: 1134px; display: block;">
            
            
            <div class="center_con js-center_con l" style="width: 1134px;">
                <div class="article-con">
                                            <!-- 买过的阅读 -->
                        

                    
                    <div class="art-title" style="margin-top: 0px;">
                        18 场景集合：并发 List、Map的应用场景
                    </div>
                    <div class="art-info clearfix">
                        
                        <span class="l">
                            更新时间：2019-10-08 16:45:03
                        </span>
                    </div>
                    <div class="art-top">
                                                <img src="https://img3.mukewang.com/5d919821000109d506400359.jpg" alt="">
                                                                        <div class="famous-word-box">
                            <img src="https://www.imooc.com/static/img/column/bg-l.png" alt="" class="bg1 bg">
                            <img src="https://www.imooc.com/static/img/column/bg-r.png" alt="" class="bg2 bg">
                            <div class="famous-word">一个不注意小事情的人，永远不会成功大事业。<p class="author">——戴尔·卡耐基</p></div>
                        </div>
                                            </div>
                    <div class="art-content js-lookimg">
                        <div id="article_content">
                            <div class="cl-preview-section"><h2 id="引导语" style="font-size: 30px;">引导语</h2>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">并发 List、Map 使用最多的就是 CopyOnWriteArrayList 和 ConcurrentHashMap，在考虑 API 时，我们也无需迟疑，这两个并发类在安全和性能方面都很好，我们都可以直接使用。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">并发的场景很多，但归根结底其实就是共享变量被多个线程同时访问，也就是说 CopyOnWriteArrayList 或 ConcurrentHashMap 会被作为共享变量，本节我们会以流程引擎为案例，现身说法，增加一下大家的工作经验积累。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">流程引擎在实际工作中经常被使用，其主要功能就是对我们需要完成的事情，进行编排和组装，比如在淘宝下单流程中，我们一共会执行 20 个 Spring Bean，流程引擎就可以帮助我们调起 20 个 Spring Bean，并帮助我们去执行，本文介绍的重点在于如何使用 Map + List 来设计流程引擎的数据结构，以及其中需要注意到的线程安全的问题。</p>
</div><div class="cl-preview-section"><h2 id="嵌套-map，简单流程引擎" style="font-size: 30px;">1 嵌套 Map，简单流程引擎</h2>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">市面上有很多流程引擎，比如说 Activiti、Flowable、Camunda 等等，功能非常齐全，但我们本小节只实现一种最最简单的流程引擎，只要能对我们需要完成的事情进行编排，并能依次的调用就行。</p>
</div><div class="cl-preview-section"><h3 id="流程引擎设计思路">1.1 流程引擎设计思路</h3>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">我们认为每个流程都会做 4 个阶段的事情，阶段主要是指在整个流程中，大概可以分为几个大的步骤，每个阶段可以等同为大的步骤，分别如下：</p>
</div><div class="cl-preview-section"><ol>
<li style="font-size: 20px; line-height: 38px;">参数校验，主要是对流程的入参数进行校验；</li>
<li style="font-size: 20px; line-height: 38px;">业务校验，主要是对当前流程中的业务进行逻辑校验；</li>
<li style="font-size: 20px; line-height: 38px;">事务中落库，主要把数据落库，控制事务；</li>
<li style="font-size: 20px; line-height: 38px;">事务后事件，我们在数据落库，事务提交之后，可能会做一些其他事情，比如说发消息出来等等。</li>
</ol>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">以上每个大的阶段，都会做一些粒度较细的事情，比如说业务校验，我们可能会对两个业务对象进行校验，那么此时业务校验阶段就会做两件事情，每件具体的事情，我们叫做领域行为，在实际项目中，一个领域行为一般都是一个 Spring Bean。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">综上所述，流程引擎嵌套数据结构就是：流程 -&gt; 阶段 -&gt; 领域行为，前者对应后者，都是一对一或者一对多的关系。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">我们以在淘宝上买东西时，下单为例，下单指的是我们在淘宝选择好了商品和优惠券后，点击购买按钮时触发的动作。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">为了方便举例，我们假设在淘宝上买电视和电影票，在后端，会分别对应着两个下单流程，我们画图示意一下：<br>
<img class="" src="https://img.mukewang.com/5d88856f000149cd12740928.png" data-original="//img.mukewang.com/5d88856f000149cd12740928.png" alt="图片描述"><br>
上图中，左右两个黑色长方形大框代表着两个流程，流程下面有多个阶段，阶段用蓝色表示，每个阶段下面有多个领域行为，用红色表示。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">可以看到两个流程中，都包含有四个阶段，阶段都是相同的，但每个阶段中的领域行为，有的相同，有的却是特有的。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">三个概念，每个概念层层嵌套，整体组装起来，用来表示一个流程，那么这个数据结构，我们应该如何表示呢？</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">使用 Map + List 即可！</p>
</div><div class="cl-preview-section"><h3 id="数据结构的定义">1.2 数据结构的定义</h3>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">流程的数据结构定义分成两步：</p>
</div><div class="cl-preview-section"><ol>
<li style="font-size: 20px; line-height: 38px;">定义出阶段、领域行为基础概念；</li>
<li style="font-size: 20px; line-height: 38px;">把阶段、领域行为、流程概念组合起来，定义出流程的数据结构。</li>
</ol>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">首先给阶段定义一个枚举，如下  StageEnum 代表流程中的阶段或步骤：</p>
</div><div class="cl-preview-section"><pre class="  language-java"><code class="prism  language-java"><span class="token keyword">public</span> <span class="token keyword">enum</span> StageEnum <span class="token punctuation">{</span>
  <span class="token function">PARAM_VALID</span><span class="token punctuation">(</span><span class="token string">"PARAM_VALID"</span><span class="token punctuation">,</span> <span class="token string">"参数校验"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>

  <span class="token function">BUSINESS_VALID</span><span class="token punctuation">(</span><span class="token string">"BUSINESS_VALID"</span><span class="token punctuation">,</span> <span class="token string">"业务校验"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>

  <span class="token function">IN_TRANSACTION</span><span class="token punctuation">(</span><span class="token string">"IN_TRANSACTION"</span><span class="token punctuation">,</span> <span class="token string">"事务中落库"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>

  <span class="token function">AFTER_TRANSACTION</span><span class="token punctuation">(</span><span class="token string">"AFTER_TRANSACTION"</span><span class="token punctuation">,</span> <span class="token string">"事务后事件"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">;</span>

  <span class="token keyword">private</span> String code<span class="token punctuation">;</span>
  <span class="token keyword">private</span> String desc<span class="token punctuation">;</span>

  <span class="token function">StageEnum</span><span class="token punctuation">(</span>String code<span class="token punctuation">,</span> String desc<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>code <span class="token operator">=</span> code<span class="token punctuation">;</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>desc <span class="token operator">=</span> desc<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">领域行为我们无需定义，目前通用的技术框架都是 Spring Boot，领域行为都是 Spring Bean，为了简单起见，我们给领域行为定义了一个接口，每个领域行为都要实现这个接口，方便我们编排，接口如下：</p>
</div><div class="cl-preview-section"><pre class="  language-java"><code class="prism  language-java"><span class="token comment">/**
 * 领域行为
 * author  wenhe
 * date 2019/8/11
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">DomainAbilityBean</span> <span class="token punctuation">{</span>

  <span class="token comment">/**
   * 领域行为的方法入口
   */</span>
  FlowContent <span class="token function">invoke</span><span class="token punctuation">(</span>FlowContent content<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>
</code></pre>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">接着我们使用 Map + List 来定义流程，定义如下：</p>
</div><div class="cl-preview-section"><pre class="  language-java"><code class="prism  language-java"><span class="token comment">/**
 * 第一个 key 是流程的名字
 * 第二个 map 的 key 是阶段，为 StageEnum 枚举，值为多个领域行为的集合
 */</span>
Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span>Map<span class="token operator">&lt;</span>StageEnum<span class="token punctuation">,</span>List<span class="token operator">&lt;</span>DomainAbilityBean<span class="token operator">&gt;&gt;&gt;</span> flowMap
</code></pre>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">至此，我们定义出了，简单流程引擎的数据结构，流程引擎看着很复杂，利用 Map + List 的组合，就巧妙的定义好了。</p>
</div><div class="cl-preview-section"><h2 id="容器初始化时，本地缓存使用" style="font-size: 30px;">2 容器初始化时，本地缓存使用</h2>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">我们定义好 Map 后，我们就需要去使用他，我们使用的大体步骤为：</p>
</div><div class="cl-preview-section"><ol>
<li style="font-size: 20px; line-height: 38px;">项目启动时，把所有的流程信息初始化到 flowMap(刚刚定义的流程的数据结构叫做 flowMap) 中去，可能是从数据库中加载，也可能是从 xml 文件中加载；</li>
<li style="font-size: 20px; line-height: 38px;">查找流程时，直接从 flowMap 中获取即可。</li>
</ol>
</div><div class="cl-preview-section"><h3 id="初始化">2.1 初始化</h3>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">以上两步最为关键的点就是 flowMap 必须是可以随时访问到的，所有我们会把 flowMap 作为共享变量使用，也就是会被 static final 关键字所修饰，我们首先来 mock 一下把所有信息初始化到 flowMap 中去的代码，如下：</p>
</div><div class="cl-preview-section"><pre class="  language-java"><code class="prism  language-java"><span class="token annotation punctuation">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">FlowCenter</span> <span class="token punctuation">{</span>

  <span class="token comment">/**
   * flowMap 是共享变量，方便访问，并且是 ConcurrentHashMap
   */</span>
  <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">final</span> Map<span class="token operator">&lt;</span>String<span class="token punctuation">,</span> Map<span class="token operator">&lt;</span>StageEnum<span class="token punctuation">,</span> List<span class="token operator">&lt;</span>DomainAbilityBean<span class="token operator">&gt;&gt;&gt;</span> flowMap
      <span class="token operator">=</span> Maps<span class="token punctuation">.</span><span class="token function">newConcurrentMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token comment">/**
   * PostConstruct 注解的意思就是
   * 在容器启动成功之后，执行 init 方法，初始化 flowMap
   */</span>
  <span class="token annotation punctuation">@PostConstruct</span>
  <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// 初始化 flowMap，可能是从数据库，或者 xml 文件中加载 map</span>
  <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">以上代码，关键地方在于三点：</p>
</div><div class="cl-preview-section"><ol>
<li style="font-size: 20px; line-height: 38px;">flowMap 被 static final 修饰，是个共享变量，方便访问；</li>
<li style="font-size: 20px; line-height: 38px;">flowMap 是 ConcurrentHashMap，所以我们所有的操作都无需加锁，比如我们在 init 方法中，对 flowMap 进行初始化，就无需加锁，因为 ConcurrentHashMap 本身已经保证了线程安全；</li>
<li style="font-size: 20px; line-height: 38px;">这里我们初始化的时机是在容器启动的时候，在实际的工作中，我们经常在容器启动的时候，把不会经常发生变动的数据，放到类似 List、Map 这样的共享变量中，这样当我们频繁要使用的时候，直接从内存中读取即可。</li>
</ol>
</div><div class="cl-preview-section"><h3 id="使用">2.2 使用</h3>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">那我们实际使用的时候，只需要告诉 flowMap 当前是那个流程的那个阶段，就可以返回该流程该阶段下面的所有领域行为了，我们写了一个流程引擎使用的工具类入口，如下：</p>
</div><div class="cl-preview-section"><pre class="  language-java"><code class="prism  language-java"><span class="token comment">// 流程引擎对外的 API</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">FlowStart</span> <span class="token punctuation">{</span>

  <span class="token comment">/**
   * 流程引擎开始
   *
   * @param flowName 流程的名字
   */</span>
  <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">start</span><span class="token punctuation">(</span>String flowName<span class="token punctuation">,</span> FlowContent content<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">invokeParamValid</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">invokeBusinessValid</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">invokeInTramsactionValid</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">invokeAfterTramsactionValid</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token comment">// 执行参数校验</span>
  <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">invokeParamValid</span><span class="token punctuation">(</span>String flowName<span class="token punctuation">,</span> FlowContent content<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">stageInvoke</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> StageEnum<span class="token punctuation">.</span>PARAM_VALID<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token comment">// 执行业务校验</span>
  <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">invokeBusinessValid</span><span class="token punctuation">(</span>String flowName<span class="token punctuation">,</span> FlowContent content<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">stageInvoke</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> StageEnum<span class="token punctuation">.</span>BUSINESS_VALID<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token comment">// 执行事务中</span>
  <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">invokeInTramsactionValid</span><span class="token punctuation">(</span>String flowName<span class="token punctuation">,</span> FlowContent content<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">stageInvoke</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> StageEnum<span class="token punctuation">.</span>IN_TRANSACTION<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token comment">// 执行事务后</span>
  <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">invokeAfterTramsactionValid</span><span class="token punctuation">(</span>String flowName<span class="token punctuation">,</span> FlowContent content<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">stageInvoke</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> StageEnum<span class="token punctuation">.</span>AFTER_TRANSACTION<span class="token punctuation">,</span> content<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
		
  <span class="token comment">// 批量执行 Spring Bean</span>
  <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">stageInvoke</span><span class="token punctuation">(</span>String flowName<span class="token punctuation">,</span> StageEnum stage<span class="token punctuation">,</span> FlowContent content<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    List<span class="token operator">&lt;</span>DomainAbilityBean<span class="token operator">&gt;</span>
        domainAbilitys <span class="token operator">=</span>
        FlowCenter<span class="token punctuation">.</span>flowMap<span class="token punctuation">.</span><span class="token function">getOrDefault</span><span class="token punctuation">(</span>flowName<span class="token punctuation">,</span> Maps<span class="token punctuation">.</span><span class="token function">newHashMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>stage<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>CollectionUtils<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>domainAbilitys<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">"找不到该流程对应的领域行为"</span> <span class="token operator">+</span> flowName<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span>DomainAbilityBean domainAbility <span class="token operator">:</span> domainAbilitys<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      domainAbility<span class="token punctuation">.</span><span class="token function">invoke</span><span class="token punctuation">(</span>content<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">从代码中可以看到，我们在流程引擎的入口，只要根据参数校验、业务校验、事务中、事务后四个阶段，从 flowMap 中得到领域行为的集合，然后对领域行为进行顺序执行即可。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">我们在使用时，直接使用上述类的 start 方法即可。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">当然以上演示的流程引擎只是一个大的框架，还有很多地方需要改进的地方，比如如何找到 flowName，如何初始化 flowMap，但这些都不是本节重点，本节主要想通过流程引擎案例来说明几点：</p>
</div><div class="cl-preview-section"><ol>
<li style="font-size: 20px; line-height: 38px;">把 List 和 Map 作为共享变量非常常见，就像咱们这种项目启动时，从数据库中把数据捞出来，然后封装成 List 或 Map 的结构，这样做的优点就是节约资源，不用每次用的时候都去查数据库，直接从内存中获取即可；</li>
<li style="font-size: 20px; line-height: 38px;">并发场景下，我们可以放心的使用 CopyOnWriteArrayList 和 ConcurrentHashMap 两个并发类，首先用 static final 对两者进行修饰，使其成为共享变量，接着在写入或者查询的时候，无需加锁，两个 API 内部已经实现了加锁的功能了；</li>
<li style="font-size: 20px; line-height: 38px;">有一点需要澄清一下，就是 CopyOnWriteArrayList 和 ConcurrentHashMap 只能作为单机的共享变量，如果是分布式系统，多台机器的情况下，这样做不行了，需要使用分布式缓存了。</li>
</ol>
</div><div class="cl-preview-section"><h2 id="总结" style="font-size: 30px;">3 总结</h2>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">本节内容，以流程引擎为例，说明了如何使用 Map + List 的嵌套结构设计流程引擎，以及在并发情况下，如何安全的使用 List 和 Map。</p>
</div><div class="cl-preview-section"><p style="font-size: 20px; line-height: 38px;">本案列是高并发项目的真实案例，感兴趣的同学可以在此流程引擎框架基础上进行细节补充，实现可运行的流程引擎。</p>
</div>}
                        </div>
                    </div>
                                            <!-- 买过的阅读 -->
                        <div class="art-next-prev clearfix">
                                                                                                <!-- 已买且开放 或者可以试读 -->
                                    <a href="/read/47/article/859">
                                                                    <div class="prev l clearfix">
                                        <div class="icon l">
                                            <i class="imv2-arrow3_l"></i>
                                        </div>
                                        <p>
                                            17 并发 List、Map源码面试题  
                                        </p>
                                    </div>
                                </a>
                                                                                                                            <!-- 已买且开放 或者可以试读 -->
                                    <a href="/read/47/article/861">
                                                                    <div class="next r clearfix">
                                        <p>
                                            19 LinkedBlockingQueue 源码解析
                                        </p>
                                        <div class="icon r">
                                            <i class="imv2-arrow3_r"></i>
                                        </div>

                                    </div>
                                </a>
                                                    </div>
                                    </div>
                <div class="comments-con js-comments-con" id="coments_con">
                </div>

                
            </div>
            
            
            

        </div>
    </div>
</div>

<div class="modal modal-jiaQun-new hide" id="modal-jiaQun">
    <div class="inner" style="">
        <div class="modal-close js-close-jiaQun">
            <i class="imv2-close"></i>
        </div>
        <div class="content">
            <img src="https://img3.mukewang.com/5d634d40000119e505400602.jpg">
            <div class="right-info">
                <div class="title">
                    扫码加入慕课Java核心用户群
                </div>
                <div class="desc">
                                            <p class="mb6">验证信息：<span id="joincode">1909271435058473</span><span class="copy js-copy-joincode">复制</span></p>
                                        <p class="mb6">QQ讨论群号：906691736</p>
                                            <p>QQ群URL：<a href="https://jq.qq.com/?_wv=1027&amp;k=55RtSbJ" target="_blank">点击访问</a></p>
                                    </div>
            </div>
            <p class="tip">若遇到搜索不到QQ群或加群失败，请联系客服邮箱:kf@imooc.com</p>
        </div>
    </div>
</div>
 
<!-- 专栏介绍页专栏评价 -->

<!-- 专栏介绍页底部三条评价 -->

<!-- 专栏阅读页弹层目录和介绍页页面目录 -->

<!-- 专栏阅读页发布回复 -->

<!-- 专栏阅读页发布评论 -->

<!-- 专栏阅读页底部评论 -->

<!-- 专栏阅读 单个 评论 -->

<!-- 新增回复和展开三条以外回复 -->

<!-- 立即订阅的弹窗 -->












</div></body></html>